package com.yonyou.pmclouds.messagenotice.constructor.impl;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.constructionlog.entity.ConstructionLogVO;
import com.yonyou.pmclouds.constructionlog.rmiitf.ConstructionLogMaintain;
import com.yonyou.pmclouds.constructionlog.rmiitf.ConstructionLogQuery;
import com.yonyou.pmclouds.messagenotice.entity.MessageNoticeVO;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
@Component
public class ConstructionLogNoticeConstructor extends AbstractMessageNoticeConstructor {

    private final ConstructionLogMaintain constructionLogMaintain;

    private final ProjectSimpleQuery projectSimpleQuery;

    private final ConstructionLogQuery constructionLogQuery;

    @Autowired
    public ConstructionLogNoticeConstructor(ConstructionLogMaintain constructionLogMaintain,
                                            ProjectSimpleQuery projectSimpleQuery,
                                            ConstructionLogQuery constructionLogQuery) {
        this.constructionLogMaintain = constructionLogMaintain;
        this.projectSimpleQuery = projectSimpleQuery;
        this.constructionLogQuery = constructionLogQuery;
    }

    @Override
    protected MessageNoticeVO[] generateContent(Entity vo) throws BusinessException {
        MessageNoticeVO noticeVO = coverBusinessVOToMessageVO(vo);
        if(noticeVO == null){
            return null;
        }
        ConstructionLogVO constructionLogVO = constructionLogQuery.queryOne(noticeVO.getRelateKey());
        ProjectVO projectVO = projectSimpleQuery.queryProject(constructionLogVO.getPk_project());

        String prefix = getApprovalPrefixMessage(constructionLogVO.getBillstatus());

        String messageContent = APPROVAL_PREFIX_MESSAGE + "[" +constructionLogVO.getInspectstandard_name()+ "]的施工记录，"  + prefix;

        noticeVO.setMessageTitle(projectVO.getSname());
        noticeVO.setMessageReceiver(constructionLogVO.getCreator());
        noticeVO.setPkTenant(constructionLogVO.getPk_tenant());
        noticeVO.setMessageContent(messageContent);
        noticeVO.setRelateType(constructionLogVO.getBill_type());

        return new MessageNoticeVO[]{noticeVO};
    }

    @Override
    public String getRelateType() {
        return BillTypeConst.CONSTRUCTIONLOG_BILLTYPE;
    }
}
